﻿using BestTrader.Cms.Core.Helper;
using BestTrader.Cms.IServices;
using BestTrader.Cms.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace BestTrader.Cms.Services
{
    public class DESEncryptService : IDESEncryptService
    {
        public string DecryptBankAccount(string bankAccount)
        {
            //var _bankAccount = string.IsNullOrEmpty(bankAccount) ? bankAccount : DESEncryptHelper.Decrypt(bankAccount);
            // 不处理银行卡的加解密 2019-04-02 杨老师 提出
            return bankAccount;
        }

        public string DecryptCardId(string cardId)
        {
            var _cardId = string.IsNullOrEmpty(cardId) ? cardId : DESEncryptHelper.Decrypt(cardId);
            return _cardId == "error" ? cardId : _cardId;
        }

        public string DecryptEmail(string email)
        {
            var _email = string.IsNullOrEmpty(email) ? email : DESEncryptHelper.Decrypt(email);
            return _email == "error" ? email : _email;
        }

        public string DecryptPhone(string phone)
        {
            var _phone = string.IsNullOrEmpty(phone) ? phone : DESEncryptHelper.Decrypt(phone);
            return _phone == "error" ? phone : _phone;
        }

        public string DecryptQQ(string qq)
        {
            var _qq = string.IsNullOrEmpty(qq) ? qq : DESEncryptHelper.Decrypt(qq);
            return _qq == "error" ? qq : _qq;
        }

        public string EncryptBankAccount(string bankAccount)
        {
            //return string.IsNullOrEmpty(bankAccount) ? bankAccount : DESEncryptHelper.Encrypt(bankAccount);
            // 不处理银行卡的加解密 2019-04-02 杨老师 提出
            return bankAccount;
        }

        public string EncryptCardId(string cardId)
        {
            return string.IsNullOrEmpty(cardId) ? cardId : DESEncryptHelper.Encrypt(cardId);
        }

        public string EncryptEmail(string email)
        {
            return string.IsNullOrEmpty(email) ? email : DESEncryptHelper.Encrypt(email);
        }

        public string EncryptPhone(string phone)
        {
            return string.IsNullOrEmpty(phone) ? phone : DESEncryptHelper.Encrypt(phone);
        }

        public string EncryptQQ(string qq)
        {
            return string.IsNullOrEmpty(qq) ? qq : DESEncryptHelper.Encrypt(qq);
        }

        /// <summary>
        /// 解密
        /// </summary>
        public Manager DecryptManagerInfo(Manager manager)
        {
            manager.CardId = DecryptCardId(manager.CardId);
            manager.Email = DecryptEmail(manager.Email);
            manager.BankCard = DecryptBankAccount(manager.BankCard);
            manager.Mobile = DecryptPhone(manager.Mobile);
            manager.QQ = DecryptQQ(manager.QQ);

            return manager;
        }

        /// <summary>
        /// 加密
        /// </summary>
        public Manager EncryptManagerInfo(Manager manager)
        {
            manager.CardId = EncryptCardId(manager.CardId);
            manager.Email = EncryptEmail(manager.Email);
            manager.BankCard = EncryptBankAccount(manager.BankCard);
            manager.Mobile = EncryptPhone(manager.Mobile);
            manager.QQ = EncryptQQ(manager.QQ);

            return manager;
        }
    }
}
